from robot.parsing import TestDataDirectory, TestCaseFile, TestCase

def get_longname(obj):
    '''Return long name of robot object

    A long name is all parent objects plus the object
    itself, separated by dots. For example:
    robot.tbs.air.test001
    '''
    longname = []
    while obj is not None:
        # The darn robot object model doesn't have a simple
        # parent/child relationship between suites and test cases.
        # The parent of a test case is a test case table rather
        # than a test suite. Go figure. So, only keep track of the
        # names of suites and test cases and not the intermediate
        # objects
        if (isinstance(obj, TestDataDirectory) or 
            isinstance(obj, TestCaseFile) or 
            isinstance(obj, TestCase)):
            longname.insert(0, obj.name)
        obj = obj.parent
    return longname
